<template>
  <div>
    <a id="downloadLink" download="资料下载" hidden class="download"></a>
    <div style="display:block;">
      <div class="masker"></div>
      <div class="c-mh24 c-p">
        <div class="content c-ph24 c-bg-white c-br10 c-pv20">
          <div class=""><img src="../../../assets/i/wap/common/ico-guide.png"></div>
          <p class="c-fs28">温馨提示</p>
          <p class="c-fs22 c-mt10 c-flex-row">点击右上角的
            <img src="../../../assets/i/wap/common/weixin-share1.png" class="imgbox">选择在浏览器打开即可下载
          </p>
        </div>
      </div>
    </div>

  </div>

</template>

<script>
import { utilJs, wxUtilJs } from "@/utils/common.js";
export default {
  name: "DatumDownload",
  data() {
    return {};
  },
  watch: {},
  methods: {
    openBrowers: function () {
      let jsApiList = [
        "onMenuShareTimeline",
        "onMenuShareAppMessage",
        "onMenuShareQQ",
        "onMenuShareWeibo",
        "onMenuShareQZone",
        "startRecord",
        "stopRecord",
        "onVoiceRecordEnd",
        "playVoice",
        "pauseVoice",
        "stopVoice",
        "onVoicePlayEnd",
        "uploadVoice",
        "downloadVoice",
        "chooseImage",
        "previewImage",
        "uploadImage",
        "downloadImage",
        "chooseWXPay",
        "hideMenuItems",
        "showMenuItems"
      ];
      utilJs.postMethod(global.apiurl + "mp/jsConfig",
        {
          jsApiList: jsApiList,
          url: window.location.href
        },
        res => {
          let data = [
            "menuItem:copyUrl",
            "menuItem:share:appMessage",
            "menuItem:share:timeline",
            "menuItem:share:qq",
            "menuItem:share:weiboApp",
            "menuItem:share:facebook",
            "menuItem:share:QZone",
            "menuItem:share:email",
            "menuItem:share:brand"
          ];
          wxUtilJs.hideMenuItems(res, data);
        }
      );
    }
  },

  activated() {
    setDocumentTitle("下载资料");// eslint-disable-line
    this.$store.commit("updateLoadingStatus", {
      isLoading: false
    });
    let downloadUrl = this.$route.query.url;
    let downloadLink = document.getElementById("downloadLink");
    downloadLink.href = downloadUrl;
    //在非微信浏览器内，直接打开下载链接，开始下载
    if (window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) != "micromessenger") {
      utilJs.appShareTrue('', '', downloadUrl, ''); // 传给app端要下载文件的地址，让他们接收进行下载。
      window.location.href = downloadUrl;
      // window.open(downloadLink)
      //IE
      // if (document.all) {
      //   downloadLink.click();
      // } else {
      //   // 其它浏览器
      //   var e = document.createEvent("MouseEvents");
      //   e.initEvent("click", true, true); //这里的click可以换成你想触发的行为
      //   downloadLink.dispatchEvent(e); //这里的clickME可以换成你想触发行为的DOM结点
      // }
    } else if (!window.location.href.includes('reload')) {
      window.open(window.location.href + '&reload=' + new Date().getTime());
    }
  },
  deactivated() { }
};
</script>
<style scoped>
.content {
  width: 90%;
  position: fixed;
  top: 1rem;
  z-index: 1003;
  max-width: 640px;
  left: 50%;
  transform: translate(-50%);
}
.content > div > img {
  width: 1.2rem;
  height: 2.2rem;
  position: absolute;
  top: 0.4rem;
  right: 0.3rem;
  z-index: 1004;
}
.imgbox {
  width: 1.6rem;
  height: 0.8rem;
  margin-left: 0.2rem;
  margin-right: 0.4rem;
}
.masker {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1002;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
}
</style>

